This notebook will examine some characterisitics of the "housing-header.txt" dataset, a dataset of housing data in Boston neighborhoods. For reference:
First we must load the dataset:
housing<-read.table("housing.header.txt", header=TRUE, sep=",")
colnames(housing)<-c("Crim", "Zn", "Indus", "Chas", "Nox", "Rm", "Age", "Dis", "Rad", "Tax", "Ptratio", "B", "Lstat", "Medv")
head(housing)
We then plot all samples with respect to the crime rate:
attach(housing)
plot(Crim)
We then continue with our example using crime rate: plotting its density as well as a histogram:
par(mfrow=c(1,2))
hist(Crim)
title ("Histogram of Crim")
plot(density(Crim, na.rm=TRUE))
We then plot crime rate, number of rooms, age of the home, and property tax rate with respect to median house value, in order to examine the correlation:
par(mfrow=c(1,4))
plot(Crim, Medv)
title("Crim-Medv")
plot(Rm, Medv)
title("Rm-Medv")
plot(Age, Medv)
title("Age-Medv")
plot(Tax, Medv)
title("Tax-Medv")
From the scatterplots, we can observe that:
We can then report the pairwise correlation between every two variables using a level plot:
cv<-cor(housing)
library(lattice)
levelplot(cv)
Observe the level plot above. The following variables are negatively correlated with Medv:
The following variables have little or no correlation with Medv:
The following variables are positively correlated with Medv:
We also demonstrate this same correlation with scatterplots:
par(mfrow=c(2, 7))
plot(Crim, Medv)
title("Crim-Medv")
plot(Zn, Medv)
title("Zn-Medv")
plot(Indus,Medv)
title("Indus-Medv")
plot(Chas, Medv)
title("Chas-Medv")
plot(Nox,Medv)
title("Nox-Medv")
plot(Rm, Medv)
title("Rm-Medv")
plot(Age, Medv)
title("Age-Medv")
plot(Dis, Medv)
title("Dis-Medv")
plot(Rad, Medv)
title("Rad-Medv")
plot(Tax, Medv)
title("Tax-Medv")
plot(Ptratio, Medv)
title("Ptratio-Medv")
plot(B, Medv)
title("B-Medv")
plot(Lstat, Medv)
title("Lstat-Medv")
The attributes that are posiitvely correlated with Medv will have a generally increasing trend on the scatterplot (x increases as y increases). The attributes that are independent of Medv will have no easily observable trend. The attributes that are negatvely correlated with Medv will have a generally decreasing trend on the scatterplot (x decreases as y increases)